package com.mszl.blog.controller;

import com.mszl.blog.entity.Category;
import com.mszl.blog.service.CategoryService;
import com.mszl.blog.vo.Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("categorys")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

//    所有的类别
    @GetMapping("all")
    public Result listCategory(){
        return categoryService.findAll();
    }

//    @GetMapping("page")
//    public ResponseEntity<Page<Category>> queryByPage(Category category, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.categoryService.queryByPage(category, pageRequest));
//    }

//    根据categoryID查找详细信息
    @GetMapping("detail/{id}")
    public Result categoriesDetailById(@PathVariable("id") Long id){
        return categoryService.categoriesDetailById(id);
    }











    @GetMapping("{id}")
    public ResponseEntity<Category> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.categoryService.queryById(id));
    }

    @PostMapping("addCategory")
    public ResponseEntity<Category> add(@RequestBody Category category) {
        return ResponseEntity.ok(this.categoryService.insert(category));
    }

    @PutMapping
    public ResponseEntity<Category> edit(@RequestBody Category category) {
        return ResponseEntity.ok(this.categoryService.update(category));
    }

    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.categoryService.deleteById(id));
    }
}
